package com.my.hzb.user.mq;

import javax.jms.*;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.my.hzb.entiy.UserMessage;
import com.my.hzb.common.util.JsonUtil;
import com.my.hzb.user.service.UserMessageService;

public class MqReceiver {

	private static final Logger log = LogManager.getLogger(MqReceiver.class);
	
	@Autowired
	private UserMessageService userMessageService;
	
	public void onMessage(String message) {
		log.info("字符串user接受的消息："+message);
        try {
        	UserMessage userMessage = JsonUtil.g.fromJson(message, UserMessage.class);
        	if(null!=userMessage){
        		userMessageService.add(userMessage);
        	}
        }catch(Exception e){
        	e.printStackTrace();
        	log.error("接受消息失败",e);
        }
	}
	
//	public void onMessage(Message message) {
//        TextMessage textMessage = (TextMessage) message;
//        try {
//        	log.info("user接受的消息："+textMessage.getText());
//        	UserMessage userMessage = JsonUtil.g.fromJson(textMessage.getText(), UserMessage.class);
//        	if(null!=userMessage){
//        		userMessageService.add(userMessage);
//        	}
//        }catch(Exception e){
//        	e.printStackTrace();
//        }
//	}
}
